//
//  BaseRefreshView.swift
//  YMSwiftUI
//
//  Created by anscen on 2022/3/23.
//
import SwiftUI
import ActivityIndicatorView
import Moya
struct BaseRefreshView: View {
    @Binding var refreshing :Bool
    var body: some View {
        GeometryReader.init { root in
            VStack(alignment: .center, spacing: 20) {
                ActivityIndicatorView(isVisible: $refreshing, type: .gradient([.white,AppColor])).frame(width: 40, height: 40, alignment: .center)
                if refreshing == false{
                    Image("icon_data_empty")
                    Text("数据空空如也...").foregroundColor(Color.appx999999()).font(Font.system(size: 16))
                }else{
                    Text("数据加载中...").foregroundColor(AppColor).font(Font.system(size: 16))
                }
            }.frame(width: root.size.width, height: root.size.height, alignment: .center)
        }
    }
}
struct BaseRefreshHeaderView: View {
    @State var refreshing :Bool
    var body: some View {
        if refreshing {
            HStack(alignment: .center, spacing: 16) {
                //ActivityIndicator(style: .medium)
                ActivityIndicatorView(isVisible: $refreshing, type: .gradient([.white,AppColor])).frame(width: 20, height: 20, alignment: .center)
                Text("加载数据中...").foregroundColor(AppColor).font(Font.system(size: 16))
            }
        } else {
            Text("放开刷新...").foregroundColor(AppColor).font(Font.system(size: 16))
        }
    }
}
struct BaseRefreshFooterView: View {
   var noMoreData :Bool
   @State var refreshing :Bool
    var body: some View {
        if noMoreData {
            Text("----我是有底线的----").foregroundColor(Color.appx999999()).font(Font.system(size: 16))
        } else {
            HStack(alignment: .center, spacing: 16) {
//                ActivityIndicator(style: .medium)
                ActivityIndicatorView(isVisible: $refreshing, type: .gradient([.white,AppColor])).frame(width: 20, height: 20, alignment: .center)
                Text("加载数据中...").foregroundColor(AppColor).font(Font.system(size: 16))
            }
        }
    }
}
struct ActivityIndicator: UIViewRepresentable {
    var style: UIActivityIndicatorView.Style
    func makeUIView(context: Context) -> some UIView {
        return UIActivityIndicatorView(style: style)
    }
    func updateUIView(_ uiView: UIViewType, context: Context) {
        if let ac = uiView as? UIActivityIndicatorView{
            ac.startAnimating()
        }
    }
}


